<?php
namespace app\common\model;

use think\Model;
class BetTing extends Model
{
	protected function initialize()
	{
		parent::initialize();
	}
	/**
	 * 彩种查找
	 * @param unknown $where
	 * @param string $order
	 */
	public function CaiZhongList($where,$order='')
	{
		return BetTing::name('caipai_list')->where($where)->order($order)->select()->toArray();
	}
	/**
	 * 投注记录查询
	 * @param unknown $sql
	 * @param unknown $where
	 * @param unknown $limit
	 * @param string $order
	 */
	public function SettlementRecordList($sql,$where,$limit,$order='')
	{
		return BetTing::name($sql)
					->alias('a')
					->field(['a.fdje','a.rktime','a.id as uid','a.czid as czid','a.qihao as qihao','a.method','a.wfid as wfid','a.username as name','a.tzje as tzje','a.dzje as dzje','a.dqpl as dqpl','a.tzhm as tzhm','a.kjjg as kjhm','a.tz_time as tz_time','a.tzhje as tzhje','a.kjjg as kjjg','a.zjzs as zjzs','a.ifqs as ifqs','a.zjje as zjje'])
					->join('__USERNAME__ u','a.username=u.username')
					->field(['u.swzh','u.nbzh'])
					->join('__PLAY_CLASSIFY__ b','b.id=a.wfid')
					->field(['b.class_name_mini as wanfa','b.digit as digit'])
					->join('__CAIPAI_LIST__ c','c.id=a.czid')
					->field(['c.cp_name_old as old_name','c.cp_name_new as new_name'])
					->where($where)->order($order)
					->paginate($limit,false,['query'=>request()->param()])->each(function($item,$key){
					    if(!empty($item['digit'])){
					        $item['tzhm'] = digit($item['tzhm'],$item['digit'],$item['czid'],$item['wfid']);
							if( strpos($item['dqpl'],'|') > -1 ){
								$item['dqpl'] = digit_pl($item['dqpl'],$item['digit'],$item['czid'],$item['wfid']);
							}
					    }
					    $item['kjjg'] = kjjg_split($item['kjjg'],$item['czid'],true);
					    return $item;
					});
	}
}